Learn how to generate sitemaps from your Algolia indices dynamically.
categories
attribute with one or more categories.
Download the dataset and import it into your Algolia application:
algolia-sitemap
as a dependency.
This helper library lets you dynamically generate sitemaps from your Algolia indices.
browse
permission.
sitemap
function, you need to add a hitsToParams
callback function.
This function turns a record from your index into a sitemap entry.
The return value of the hitsToParams
function must be an object with attributes
that match an <url>
entry of a sitemap file:
loc
(required): the URL of the page for the recordlastmod
: the last modified date (ISO 8601)priority
: the priority of this page compared to other pages on your site (between 0 and 1)changefreq
: describes how often the page is likely to changealternates
: alternate versions of this linkalternates.languages
: an array of enabled languages for this linkalternates.hitToURL
: a function that transforms a language into a URLloc
attribute.
sitemaps/
directory.
Now, you can run the sitemap.js
script:
/sitemaps
directory now has two types of files:
sitemap-index.xml
file with links to each sitemap filesitemap.0.xml
file with links to your productsxmllint
.
categories
attribute for the URL:
https://example.com/{CATEGORY_NAME}
.
You need to modify the hitToParams
callback function to return an array of all categories that belong to a given record.
Since categories apply to many records, you need to make sure to add them to your sitemaps only once.
With ES6, you can use a Set
.
ping
mechanism to inform them of a new sitemap,
so you can perform this directly from your script.